package bman.game.engine;

import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

/**
 * 
 * @author MrJacky
 *
 */
public class Controller
{
	GameConsole console;
	long lastCommand;
	
	public Controller(GameConsole console)
	{
		this.console = console;
	}
	
	public void perform(KeyEvent ke)
	{
		/*
		 * Do not allow too many commands
		 */
		long l = System.currentTimeMillis() - lastCommand;
		if(l < 25)
		{
			return;
		}
		else
		{
			lastCommand = System.currentTimeMillis();
		}
		
		console.performAction(convert(ke.getKeyCode()));
	}
	
	public String convert(int keyCode)
	{
		switch(keyCode)
		{
			case KeyEvent.VK_LEFT:
				return "MOVE WEST";
				
			case KeyEvent.VK_RIGHT:
				return "MOVE EAST";
				
			case KeyEvent.VK_UP:
				return "MOVE NORTH";
				
			case KeyEvent.VK_DOWN:
				return "MOVE SOUTH";
			case KeyEvent.VK_SPACE:
				return "FIRE";
				
			default:
				return null;
		}
	}
}
